#include "img.h"
#include "../memory.h"
#include "../render.h"



may_img_t *img_create(void *parent, int x, int y, int w, int h, const uint8_t *imgSrc)
{
    may_img_t *img = (may_img_t *)memory_alloc(sizeof(may_img_t));

    img->obj.widget_type = widget_type_img;
    img->obj.x = x;
    img->obj.y = y;
    img->obj.h = h;
    img->obj.w = w;
    img->imgSrc = imgSrc;

    if(parent)
    {
    list_add_tail(&img->obj.node, &((widget_t *)parent)->node);
    }
    return img;
}

void img_remove(may_img_t *img)
{
    list_del(&img->obj.node);
    memory_free(img);
}

void img_set_imgSrc(may_img_t *img, const uint8_t *imgSrc)
{
    img->imgSrc = imgSrc;
}

void img_render(void *obj)
{
    may_img_t* img = (may_img_t*)obj;
    render_draw_img(img->obj.x, img->obj.y, img->obj.w, img->obj.h, img->imgSrc);
}